import { BaseEntity } from 'src/common/base.entity'
import { User } from 'src/users/entities/user.entity'
import { Entity, Column, ManyToOne, OneToMany } from 'typeorm'
import { Photo } from './photo.entity'

export enum ItemStatus {
  DRAFT = 'DRAFT', // 草稿，还未发布
  AVAILABLE = 'AVAILABLE', // 已发布，其他用户可以下单
  REQUEST = 'REQUEST', // 求购物品
  PAUSE = 'PAUSE', // 暂时下架
  SOLD = 'SOLD', // 买家已拍下
  DEAL = 'DEAL' // 交易完成
}

@Entity()
export class Item extends BaseEntity {
  @Column()
  name: string

  @Column()
  description: string

  @Column()
  price: number

  @Column({ nullable: true })
  shippingFee?: number

  @Column({ nullable: true })
  originalPrice?: number

  @Column({
    type: 'enum',
    enum: ItemStatus,
    default: [ItemStatus.DRAFT]
  })
  status: ItemStatus

  @OneToMany(() => Photo, (photo) => photo.item, { eager: true })
  photos: Photo[]

  @ManyToOne(() => User, (user) => user.items)
  user: User
}
